package com.weipai.education.controller;

import com.weipai.education.model.UserCategory;
import com.weipai.education.model.api.Response;
import com.weipai.education.service.UserCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * @Author: 曹朋飞
 * @Date: 2018/12/10 14:59
 * 
 * 经销商类别
 */
@RestController
@Validated
public class UserCategoryController {
    
    @Autowired
    private UserCategoryService userCategoryService;

    /**
     * 分页查询
     * @param page
     * @param size
     * @return
     */
    @RequestMapping(value = "/userCategory/list", method = RequestMethod.GET)
    public Response list(@NotNull(message = "page不能为空") @RequestParam(value = "page") Integer page,
                         @NotNull(message = "size不能为空") @RequestParam(value = "size") Integer size,
                         @RequestParam(value = "dispark", required = false) String dispark){
        return userCategoryService.list(page, size, dispark);
    }
    
    /**
     * 经销商类别保存--修改
     * @param userCategory
     * @return
     */
    @RequestMapping(value = "/userCategory/save", method = RequestMethod.POST)
    public Response save(@Valid UserCategory userCategory){
        return userCategoryService.save(userCategory);
    }

    /**
     * 更改经销商类别的状态
     * @param id
     * @return
     */
    @RequestMapping(value = "/userCategory/changeStatus", method = RequestMethod.GET)
    public Response changeStatus(@NotBlank(message = "类别id不能为空") String id){
        return userCategoryService.changeStatus(id);
    }

    /**
     * 批量删除
     * @param id:
     * @return
     */
    @RequestMapping(value = "/userCategory/batchDeleteById", method = RequestMethod.GET)
    public Response batchDeleteById(@NotNull(message = "类别id不能为空") String[] id){
        return userCategoryService.batchDeleteById(id);
    }
    
}
